
/*
  Timer Test  
 */
 
#include "Wire.h"
#include <DS1107H.h>

DS1107H clock;
char ch;
int v = 0;

void setup() { 
  Serial.begin(9600);  
  //to set the timer chip  
  
  byte second=0;
  byte minute=04;
  byte hour=21;
  byte dayOfWeek=2;
  byte dayOfMonth=6;
  byte month=1;
  byte year=15;
  //clock.setDate(second,minute,hour,dayOfWeek,dayOfMonth,month,year);    
  
  
}

void loop() { 
 if (Serial.available()) { 
      ch = Serial.read();  
      switch(ch) {
       case '0'...'9':
          v = v * 10 + ch - '0';
          break;
        case 'e':
          showln("test val:",v);                      
          v = 0; break; 
        case 'i':
          showln("inc Second:",v);  
          incSec(clock);
          v = 0; break;
        case 't':
        showln("time",0);
        showTime(clock);
        v=0; break;        
    }
  }   
  
}

void showln(char nameStr[], double val) {
  Serial.print(nameStr);    
  Serial.println(val);
  
}

void incSec(DS1107H tc) {
  showTime(tc);
  tc.getDate();
  tc.second++;
  clock.setDate(tc.second,tc.minute,tc.hour,tc.dayOfWeek,tc.dayOfMonth,tc.month,tc.year);
  showTime(tc);
}

void showTime(DS1107H timerChip) {  
  timerChip.getDate();
  Serial.print("   UT ");
  Serial.print(timerChip.hour, DEC);
  Serial.print(":");
  Serial.print(timerChip.minute, DEC);
  Serial.print(":");
  Serial.print(timerChip.second, DEC);
  Serial.print("  ");
  Serial.print(timerChip.month, DEC);
  Serial.print("/");
  Serial.print(timerChip.dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(timerChip.year, DEC);
  Serial.print("  Day_of_week:");
  Serial.println(timerChip.dayOfWeek, DEC);  
}
